<template>
  <div>
    <!-- 缓存model下面子页面 -->
    <!-- <keep-alive>
      <router-view v-if="$route.meta.keepAlive" />
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" /> -->

    <!-- 最简单的路由页面切换 -->
    <transition
      enter-active-class="animate__animated animate__fadeInLeft"
      leave-active-class="animate__animated animate__fadeOutRight"
      mode="out-in"
    >
      <router-view />
    </transition>
  </div>
</template>
<script>

</script>



<!-- 页面切换动画transitionName -->
<!-- <template>
  <div>
  
    <transition :name="transitionName">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"></router-view>
      </keep-alive>
    </transition>
    <transition :name="transitionName">
      <router-view v-if="!$route.meta.keepAlive"></router-view>
    </transition>
  </div>
</template>
<script>
export default {
  name: 'model',
  data () {
    return {
      transitionName: ""
    }
  },
  watch: {
    $route (to, from) {
      /*判断路由层级index*/
      // if (to.meta.index > 0 && from.meta.index) {
      //   if (to.meta.index < from.meta.index) {
      //     this.transitionName = "slide-right";
      //   } else {
      //     this.transitionName = "slide-left";
      //   }
      // } else if (to.meta.index == 0 && from.meta.index > 0) {
      //   this.transitionName = "";
      // }
      this.transitionName = "slide-right";
    }
  }
}
</script>
<style lang="less" >
/* 页面切换动画 */
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  /* will-change属性可以提前通知浏览器我们要对元素做什么动画，这样浏览器可以提前准备合适的优化设置 */
  will-change: transform;
  transition: all ease 0.4s;
  -webkit-transition: all ease 0.4s;
  position: absolute;
  width: 100%;
  left: 0;
}

.slide-right-enter {
  transform: translateX(-100%);
  -webkit-transform: translateX(-100%);
}

.slide-right-leave-active {
  transform: translateX(100%);
  -webkit-transform: translateX(100%);
}

.slide-left-enter {
  transform: translateX(100%);
  -webkit-transform: translateX(100%);
}

.slide-left-leave-active {
  transform: translateX(-100%);
  -webkit-transform: translateX(-100%);
}
</style> -->